<template>
	<view class="page login aliC home">
		<image class="logo  r50" src="/static/logo.jpg" mode="aspectFill"></image>
		<view class="mt14"></view>
		<view  class="px40 mt90"><button  open-type="getPhoneNumber" class="bglineEb fs16 py4 btn bgf6c" @getphonenumber="getPhone">手机号一键登录</button></view>
		<view  class="px40 mt20"><button @click="cancel()" class="bglineEb fs16 py4 btn bgf6c">取消</button></view>
		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				agent: 1,
				provider:'',
				code:'',
				shareCode:'',
				infoData:'',
				infoIv:'',
				session_key:'',
				code:'',
				ref_mobile:'',
				shop_id:'',
				userIv:'',
				userData:''
				
			};
		},
		
		onLoad(options) {
			this.init();
		
			
		},
		methods:{
			cancel(){
				uni.switchTab({
					url: '/pages/home/index2'
				})
			},
			
			init() {
			
				let _this = this;
				uni.getProvider({
					service: 'oauth',
					success: function(res) {
						let provider = res.provider;
						_this.provider = provider;
						uni.setStorageSync("provider", provider)
					},
					fail: function(res) {
			
					}
				});
				uni.login({
					provider: uni.getStorageSync("provider"),
					success: function(loginRes) {
						console.info(loginRes);
						let code = loginRes.code;
						_this.code = code;
						
			
					},
					fail: function(res) {
			
					}
				})
			},
			
			login() {
			
				this.$refs.loginPopup.close()
				if (this.code == '') {
					uni.showToast({
						title: '初始化系统数据',
						icon: 'none'
					});
					return;
				}
			
				let that = this;
				uni.getUserProfile({
					desc: '会员登录',
					success(res) {
						console.info(res);
						var iv = res.iv;
						var encryptedData = res.encryptedData;
						that.userIv = iv;
						that.userData = encryptedData;
					},
					fail(err) {
						console.info(err);
			
					}
				})
			},
			
			getPhone(e) {			
				var phoneData = e.detail.encryptedData;
				var phoneIv = e.detail.iv;
				var codeMsg = e.detail.errMsg;
				
				let param = {
					phoneData: phoneData,
					phoneIv: phoneIv,
					code: this.code,
					orgId:27
				}
			
				let that = this;
				this.$api.auth(param).then(res => {
			
					if (res.code == 1) {
						uni.setStorageSync("mobile", res.data.mobile);
						uni.setStorageSync("token", res.data.token);
						uni.setStorageSync("avatar", res.data.avatar);
						uni.navigateBack({
							delta:2
						})
			
					} else {
						that.init();
					}
					console.info(res);
				})
			},
	
	}
}
</script>

<style lang="scss" scoped>
.login {padding-top: 220upx;
	.logo {width: 210upx;height: 210upx;}
	.mt90 {margin-top: 180upx;}
	.checkbox {width: 26upx;height: 26upx;display: inline-block;}
	.fixed{position: absolute;bottom: 30upx;left: 0;width: 100%;}
	button{
		height: 80upx;
		line-height: 60upx;
	}
}

	.home {
		.w40 {
			width: 80upx;
			height: 80upx;
		}

		.w18 {
			width: 36upx;
			height: 36upx;
		}

		.h35 {
			height: 70upx;
			line-height: 70upx;
		}

		.lins {
			position: relative;

			&::after {
				content: '';
				width: 60upx;
				height: 4upx;
				background-color: #FF0000;
				position: absolute;
				bottom: -4upx;
				left: calc(50% - 30upx)
			}
		}

		.w106 {
			width: 100%;
			height: 212upx;
		}

		.w20 {
			width: 40upx;
		}
	}
</style>
